import 'package:flutter/material.dart';
import 'package:flutterlib/common/net/dao_result.dart';
import 'package:flutterlib/common/net/retrofit/post_api.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/utils.dart';
import 'package:flutterlib/model/post/comment_bean.dart';
import 'package:flutterlib/model/post/comment_bean_tree.dart';
import 'package:flutterlib/pages/base/base_sliver_list.dart';
import 'package:flutterlib/widgets/back_button.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';
import 'package:flutterlib/widgets/pull/nested/simple_pull_load_manger.dart';

class ActivityCommentListPage extends BaseSliverList {
  final int activityId;

  ActivityCommentListPage({Key key, this.activityId})
      : super(key: key);

  @override
  ActivityCommentListPageState createState() => ActivityCommentListPageState();
}

///页面 KeepAlive ，同时支持 动画Ticker
class ActivityCommentListPageState
    extends BaseSliverListState<ActivityCommentListPage> {
  SimplePullLoadManger manger;

  ///滑动监听
  final ScrollController scrollController = new ScrollController();

  getDataLogic(int page) async {
    print(page);
    CommentBeanTree pageByQuery = await PostApi.builder()
        .commentPageByQuery(widget.activityId, page - 1, "createTime,desc");
    return new DataResult(pageByQuery?.content, true);
  }

  Widget renderItem(index, comment) {
    //提交
    // var activity = pullLoadWidgetControl.dataList[index];
    return CommentItem(comment);
  }

  @override
  List<Widget> renderHeader(BuildContext context, bool innerBoxIsScrolled) {
    return <Widget>[];
  }

  @override
  renderActions() {
    return <Widget>[];
  }

  @override
  Widget renderLeading() {
    return MyBackButton(
      color: Colors.black,
    );
  }

  @override
  Widget renderTitle() {
    return Text("评论", style: QuhuiConstant.normalTextBold);
  }

  @override
  bool enablePullDown() {
    return true;
  }

  @override
  bool enablePullUp() {
    return true;
  }
}




class CommentItem extends StatelessWidget {
  final CommentBean commentBean;

  const CommentItem(this.commentBean, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: UserInfoWidget(
        onPressed: () {
          NavigatorUtils.goUserHome(context, commentBean.userId);
        },
        width: 33,
        height: 33,
        image: commentBean.authorLogo,
      ),
      title: Text(
        commentBean.author,
        style: QuhuiConstant.minSubGray6Text,
      ),
      subtitle: Text(
        commentBean.content,
        style: QuhuiConstant.smallText,
      ),
    );
  }
}
